package org.jash.shop2201.utils

import android.content.Context
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import org.jash.shop2201.database.ShopDatabase
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {
    @Singleton
    @Provides
    fun getSrc() = "Hilt 注入"
    @Singleton
    @Provides
    fun getDB(@ApplicationContext app:Context) = Room.databaseBuilder(app, ShopDatabase::class.java, "shop")
        .fallbackToDestructiveMigration()
        .build()
    @Singleton
    @Provides
    fun getGoodsDao(db:ShopDatabase) = db.getGoodsDao()
}